package com.rq.viewtestapplication;

import android.graphics.Canvas;
import android.graphics.Paint;

import java.util.ArrayList;
import java.util.List;

/**
 * 直线连接
 */
public class LineLink implements LinkImpl {
    List<ViewInfo> bind = new ArrayList<>();

    public void attach(ViewInfo info) {
        bind.add(info);
    }


    public void draw(Canvas canvas, Paint focus) {
        if (bind.size() == 2) {
            int[] rect = calcX();
            if (rect == null) return;
            canvas.drawLine(rect[0], rect[1], rect[2], rect[3], focus);
        }
    }

    private int[] calcX() {
        FeaturePoint point1 = FeaturePoint.generatePoint(bind.get(0).getView());
        FeaturePoint point2 = FeaturePoint.generatePoint(bind.get(1).getView());
        if (point1.closeTo(point2) == 5) {
            LOG.e("LineLink", "34:");
            return null;
        }
        int tag = point1.closeTo(point2);
        if (tag % 2 == 0) {
            return FeaturePoint.getCloseCenterPoint(point1, point2);
        }
        return FeaturePoint.getClosePoint(point1, point2);
    }
}
